home *** CD-ROM | disk | FTP | other *** search
- unit Port;
-
- { Written by Andrew Clark, andyc@rmpd-ngh.demon.co.uk }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs;
-
- type
-
- EPortError = class(Exception);
-
- TPort = class(TComponent)
- private
- { Private declarations }
- procedure Outport(Address,Data:Word);
- function InPort(Address:Word):Word;
- protected
- { Protected declarations }
- public
- { Public declarations }
- constructor Create(AOwner:TComponent);override;
- property Port[index:Word]:Word read InPort write OutPort;default;
- published
- { Published declarations }
- end;
-
- procedure Register;
-
- implementation
-
- procedure TPort.OutPort(Address,Data:Word);
- asm
- mov dx,Address
- mov ax,Data
- out dx,ax
- end;
-
- function TPort.InPort(Address:Word):Word;
- asm
- mov dx,Address
- in ax,dx
- end;
-
- constructor TPort.Create(AOwner:TComponent);
- var
- h:Integer;
- begin
- Inherited Create(AOwner);
- Inherited Create(AOwner);
- { load the driver }
- h:=CreateFile('\\.\\giveio',GENERIC_READ,0,nil,
- OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
-
- { warn if driver not there }
- if H=INVALID_HANDLE_VALUE then
- raise EPortError.Create('GiveIO Driver Not Installed');
-
- { we don't actually need the handle, as loading the driver
- enables the free port access for the period of the program }
- CloseHandle(h);
- end;
-
- procedure Register;
- begin
- RegisterComponents('AndyC', [TPort]);
- end;
-
- end.